package org.linlinjava.litemall.db.service.distribution;


import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.DisProfitParamMapper;
import org.linlinjava.litemall.db.domain.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 参数设置Dao
 *
 * @author huangpu
 * @Date 2018-04-06 11:33:32
 */
@Service
public class DisProfitParamService {
    @Autowired
    private DisProfitParamMapper paramMapper;


    public void save(DisProfitParam param) {
        param.setIsDelete("N");
        paramMapper.insert(param);
    }

    public void delete(int id) {
    }


    public DisProfitParam getByGoodsId(Integer goodsId) {
        List<DisProfitParam> list = paramMapper.getByGoodsId(goodsId);
        if(list!=null && list.size()>0){
            return list.get(0);
        }
       return  null;
    }

    public List<DisProfitParam> querySelective(String goodsId, Integer page, Integer limit) {

        DisProfitParamExample example = new DisProfitParamExample();
        DisProfitParamExample.Criteria criteria = example.createCriteria();

        if (!StringUtils.isEmpty(goodsId)) {
            criteria.andDisGoodsIdEqualTo(Integer.parseInt(goodsId));
        }
        PageHelper.startPage(page, limit);
        return paramMapper.selectByExample(example);
    }

    public int countSeletive(String goodsId, Integer page, Integer limit) {
        DisProfitParamExample example = new DisProfitParamExample();
        DisProfitParamExample.Criteria criteria = example.createCriteria();

        if (!StringUtils.isEmpty(goodsId)) {
            criteria.andDisGoodsIdEqualTo(Integer.parseInt(goodsId));
        }
        PageHelper.startPage(page, limit);
        return (int)paramMapper.countByExample(example);
    }

    public void update(DisProfitParam info) {
        paramMapper.updateByPrimaryKey(info);
    }

    public DisProfitParam getById(Integer id) {
        return paramMapper.selectByPrimaryKey(id);
    }
}
